package com.aosiding.demo.controller;

import com.aosiding.demo.domain.User;
import com.aosiding.demo.service.CRUDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CRUDController {

    @Autowired
    private CRUDService crudService;


    @PostMapping("/C")
    public boolean createUser(@RequestBody User user){
        boolean flag = crudService.createUser(user);
        return flag;
    }

    //获取所有用户
    @GetMapping("/R")
    public List<User> getAllUser(){
        List<User> userList = crudService.getAllUser();
        return userList;
    }

    //根据id获取用户信息
    @GetMapping("/R/{id}")
    public User getUserById(@PathVariable Long id){
        User user = crudService.getUserById(id);
        return user;
    }

    //根据id删除用户
    @DeleteMapping("D/{id}")
    public boolean deleteById(@PathVariable Long id){
        boolean flag = crudService.deleteById(id);
        return flag;
    }

    @PostMapping("U")
    public boolean updateById(@RequestBody User user){
        boolean flag = crudService.updateById(user);
        return flag;
    }
}
